import path from 'path';
import db from '../../data/db';
const TABLE = path.basename(__dirname);//默认表名称为当前文件夹名称
const model = db.get(TABLE);
export function get({pageSize = 0, page = 0} = {}) {
    const ps = model;
    return pageSize && page
        ? ps.fetchPage({pageSize, page})
        .then(result =>
            ps.count().then(
                count => ({
                    count,
                    data: result
                }))
        )
        : ps.fetchAll();
}

export function save(data) {
    return new model(data).save();
}

export function del(id) {
    return model.forge({Id: id}).destroy();
}
